package com.panda.takeaway.controller;


import com.panda.takeaway.entity.bo.CreateOrderBo;
import com.panda.takeaway.entity.bo.OrderBo;
import com.panda.takeaway.entity.dto.CommonResult;
import com.panda.takeaway.entity.dto.PageBean;
import com.panda.takeaway.entity.vo.PageInfoVo;
import com.panda.takeaway.service.OrderService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author xdf
 * @Package com.panda.takeaway.controller
 */
@RestController
@RequestMapping("/api/order")
public class OrderController {
    @Resource
    private OrderService orderService;

    @RequestMapping("/merchant/queryOrder")
    @PreAuthorize("hasAuthority('queryOrder')")
    public CommonResult<PageBean<OrderBo>> merchantQueryOrder(@RequestBody OrderBo orderBo, @RequestParam("tele") String merchant, @RequestParam("page") int page) {
        return orderService.merchantQueryOrder(orderBo, merchant, page);
    }

    @RequestMapping("/merchant/getOrderByStatus")
    @PreAuthorize("hasAuthority('getOrderByStatus')")
    public CommonResult<PageBean<OrderBo>> merchantGetOrderByStatus(@RequestParam("userId") Long userId, @RequestParam byte status, @RequestBody PageInfoVo pageInfoVo) {
        return orderService.merchantGetOrderByStatus(userId, status, pageInfoVo);
    }

    @RequestMapping("/customer/queryOrderByNumber")
    @PreAuthorize("hasAuthority('queryOrder')")
    public CommonResult<OrderBo> customerQueryOrder(@RequestBody OrderBo orderBo, @RequestParam("userId") Long userId) {
        return orderService.customerQueryOrder(userId, orderBo);
    }

    @RequestMapping("/arrangeOrder")
    @PreAuthorize("hasAuthority('arrangeOrder')")
    public CommonResult<String> arrangeOrder(@RequestParam("userId") Long userId, @RequestBody OrderBo orderBo) {
        return orderService.arrangeOrder(orderBo.getNumber(), orderBo.getStatus(), userId);
    }

    @RequestMapping("/createOrder")
    @PreAuthorize("hasAuthority('createOrder')")
    public CommonResult<String> createOrder(@RequestBody CreateOrderBo createOrderBo){
        return orderService.createOrder(createOrderBo);
    }
    @RequestMapping("/customer/getOrderByStatus")
    public CommonResult<PageBean<OrderBo>> customerGetOrderByStatus(@RequestBody PageInfoVo pageInfoVo,@RequestParam("userId") Long userId, @RequestParam byte status){
        return orderService.customerGetOrderByStatus(userId,status,pageInfoVo);
    }
}
